import { computed, reactive } from "vue";
import { defineStore } from "pinia";

export const useTagStore = defineStore("tags", () => {
    const tags = reactive(JSON.parse(localStorage.getItem("tags")) || []);
    const gettags = computed(() => tags);
    console.log(tags);
    function addTag(tag) {
        if (!tags.includes(tag)) {
            tags.push(tag)
            localStorage.setItem("tags", JSON.stringify(tags))
        }
    }
    function removeTag(tag) {
        let index = tags.indexOf(tag)
        if (index >= 0) {
            tags.splice(index, 1)
            localStorage.setItem("tags", JSON.stringify(tags))
        }
    }
    return { gettags, addTag, removeTag };
});
